Rem ****************************************
Rem * Shell3a external command - setpr.opl
Rem * ¸ Nick Murray May 1996
Rem *
Rem * setpr - Change the priority of the
Rem *        specified process
Rem ****************************************
PROC setpr%:(n%)
LOCAL ax%,bx%,cx%,dx%,si%,di%
LOCAL ret%,buf$(15),str%,addr%,pattern$(2)
	ONERR ErrTrap::
	If n%<>3
		IF n%=2
			bx%=CALL($0088)	Rem no process so use current one
		ELSE
			PRINT "Usage: setpr <priority> <process id>"
			RETURN
		ENDIF
	ELSE
Rem get the name of the process to change the priority of
		bx%=EVAL(PEEK$(argv%(3)))
		addr%=ADDR(buf$)
		pattern$="*"+CHR$(0)
		DO
			str%=ret%
			ret%=CALL($0B88,ret%,0,0,UADD(addr%,1),UADD(ADDR(pattern$),1))
			IF ret%=bx%
				POKEB addr%,CALL($B9,0,0,0,0,UADD(addr%,1))
				ret%=EVAL(RIGHT$(buf$,2))
				IF ret%<7
					PRINT "System process:",buf$
				ELSE
					GOTO Found::
				ENDIF
				RETURN
			ENDIF
		UNTIL ret%=str%
		PRINT "Process not found"
		RETURN
	ENDIF	
Found::	Rem bx%=valid process id
	ax%=EVAL(PEEK$(argv%(2)))
	IF ax%>255 OR ax%<0
		PRINT "Priority must be 0-255"
		RETURN
	ENDIF
	ax%=ax%+$300
	OS($88,ADDR(ax%))
	RETURN
ErrTrap::
	ONERR off
	PRINT err$:(ERR)
ENDP
